
package node;

import java.io.Serializable;
import java.rmi.Remote;
import java.rmi.RemoteException;
import message.Message;

/**
 * Interface to the actual node class.
 * 
 * @author team6
 * @version 5/7/2013.
 */
public interface Node extends Remote
{

  /**
   * Clients call this method to get the value of this specific key.
   * 
   * @param the_key is the key.
   * @return a message that includes the value that maps to this key.
   * @throws RemoteException if there is a problem completing the method call.
   */
  Serializable get(final String the_key) throws RemoteException;

  /**
   * Clients call this method to put a key-value entry into this distributed
   * HashTable system. The entry stores into appropriate place.
   * 
   * @param the_key is the key.
   * @param the_data is the map value.
   * @return serializable

   * @throws RemoteException if there is a problem completing the method call.
   */
  Serializable put(final String the_key, final Serializable the_data) throws RemoteException;

  /**
   * Gets the ID of this node.
   * 
   * @return the ID.
   * @throws RemoteException if there is a problem completing the method call.
   */
  int getMyID() throws RemoteException;

  /**
   * Checks if this node contains the virtual node.
   * 
   * @param the_virtual is the virtual node.
   * @return true if the virtual node belongs or equals to this node otherwise,
   *         false.
   * @throws RemoteException if there is a problem completing the method call.
   */
  boolean containVirtual(final int the_virtual) throws RemoteException;

  /**
   * Get the M value of the system.
   * 
   * @return the m value
   * @throws RemoteException if there is a problem completing the method call.
   */
  int getMValue() throws RemoteException;

  /**
   * To push the message to next node. 
   * @param the_request message
   * @return node
   * @throws RemoteException 
   */
  Node nextHop(final Message the_request) throws RemoteException;

  /**
   * Data transfer after deleting the data.
   * @throws RemoteException  
   */
  void initializeDataTransfer_Delete() throws RemoteException;

  /**
   * Sends the message to the node.
   * @param the_message message
   * @throws RemoteException 
   */
  void process_message(final Message the_message) throws RemoteException;
 

  /**
   * Re-initialize the system.
   * @throws RemoteException 
   */
  void reinitialize() throws RemoteException;

  /**
   * Processes the put, get, clear, remove request in the destination node.
   * 
   * @param the_request is the request.
   * @throws RemoteException if problem happens during the remote call.
   */
  void processRequest(Message the_request) throws RemoteException;

  
  /**
   * Send the message.
   * @param message
   * @throws RemoteException
   */
  void send_message(Message message) throws RemoteException;

  
  /**
   * Initialize the system.
   * @throws RemoteException 
   */
  void initialize() throws RemoteException;

  /**
   * Updates the actual nodes after deleting / adding the node to the system.
   * @throws RemoteException  
   */
  void updateActualNodes() throws RemoteException;

  
  /**
   * Data transfer for new the node is added.
   * @throws RemoteException 
   */
  void initializeDataTransfer_Add() throws RemoteException;

  /**
   * Updates the channels after deleting/ adding a node. 
   * @return true if the update network is successfully else false.
   * @throws RemoteException 
   */
  boolean updateNetworkChannels() throws RemoteException;
  

 

  

  /**
   * Unpacks the virtual node data from message and stores it locally.
   * @param the_message is the message contains virtual node.
   * @throws RemoteException if problems happen during the remote call.
   */
  void unloadVirtualNodeData(Message my_message) throws RemoteException;
 
  /**
   * Packs all virtual data into message and send them back to the request node.
   * @param the_message is the message asks for virtual node.
   * @throws RemoteException if problems happen during the remote call.
   */
  void loadVirtualNodeData(Message the_message) throws RemoteException;
  
  /**
   * Deletes the virtual nodes after passing it to the other actual node and got ack.
   * @param the_message is the message.
   * @throws RemoteException if problems happen during the remote call.
   */
  void deleteTransferedVirtualNodes(final Message the_message) throws RemoteException;


  /**
   * Re-Initialize the channels after deleting/adding node.
   * @throws RemoteException if problems happen during the remote call.
   */
  void reinitializeChannels() throws RemoteException;

  
  /**
   * kills the nodes when  node is deleted.
   * @param the_message is the message.
   * @throws RemoteException if problems happen during the remote call.
   */
  void initializeShutDown(final Message the_message) throws RemoteException;
  

}
